using Microsoft.AspNetCore.Mvc;
using JTZY.Model.Business.Dto;
using JTZY.Model.Business;
using JTZY.Service.Business.IBusinessService;
using JTZY.Admin.WebApi.Filters;

//创建时间：2024-10-26
namespace JTZY.Admin.WebApi.Controllers.Business
{
    /// <summary>
    /// 地区表
    /// </summary>
    [Verify]
    [Route("business/Corecmsarea")]
    public class CorecmsareaController : BaseController
    {
        /// <summary>
        /// 地区表接口
        /// </summary>
        private readonly ICorecmsareaService _CorecmsareaService;

        public CorecmsareaController(ICorecmsareaService CorecmsareaService)
        {
            _CorecmsareaService = CorecmsareaService;
        }

        /// <summary>
        /// 查询地区表列表
        /// </summary>
        /// <param name="parm"></param>
        /// <returns></returns>
        [HttpGet("list")]
        [ActionPermissionFilter(Permission = "corecmsarea:list")]
        public IActionResult QueryCorecmsarea([FromQuery] CorecmsareaQueryDto parm)
        {
            var response = _CorecmsareaService.GetList(parm);
            return SUCCESS(response);
        }

        /// <summary>
        /// 查询地区表列表树
        /// </summary>
        /// <param name="parm"></param>
        /// <returns></returns>
        [HttpGet("treeList")]
        [ActionPermissionFilter(Permission = "corecmsarea:list")]
        public IActionResult QueryTreeCorecmsarea([FromQuery] CorecmsareaQueryDto parm)
        {
            var response = _CorecmsareaService.GetTreeList(parm);
            return SUCCESS(response);
        }

        /// <summary>
        /// 查询地区表详情
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        [HttpGet("{Id}")]
        [ActionPermissionFilter(Permission = "corecmsarea:query")]
        public IActionResult GetCorecmsarea(int Id)
        {
            var response = _CorecmsareaService.GetInfo(Id);
            
            var info = response.Adapt<CorecmsareaDto>();
            return SUCCESS(info);
        }

        /// <summary>
        /// 添加地区表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [ActionPermissionFilter(Permission = "corecmsarea:add")]
        [Log(Title = "地区表", BusinessType = BusinessType.INSERT)]
        public IActionResult AddCorecmsarea([FromBody] CorecmsareaDto parm)
        {
            var modal = parm.Adapt<Corecmsarea>().ToCreate(HttpContext);

            var response = _CorecmsareaService.AddCorecmsarea(modal);

            return SUCCESS(response);
        }

        /// <summary>
        /// 更新地区表
        /// </summary>
        /// <returns></returns>
        [HttpPut]
        [ActionPermissionFilter(Permission = "corecmsarea:edit")]
        [Log(Title = "地区表", BusinessType = BusinessType.UPDATE)]
        public IActionResult UpdateCorecmsarea([FromBody] CorecmsareaDto parm)
        {
            var modal = parm.Adapt<Corecmsarea>().ToUpdate(HttpContext);
            var response = _CorecmsareaService.UpdateCorecmsarea(modal);

            return ToResponse(response);
        }

        /// <summary>
        /// 删除地区表
        /// </summary>
        /// <returns></returns>
        [HttpPost("delete/{ids}")]
        [ActionPermissionFilter(Permission = "corecmsarea:delete")]
        [Log(Title = "地区表", BusinessType = BusinessType.DELETE)]
        public IActionResult DeleteCorecmsarea([FromRoute]string ids)
        {
            var idArr = Tools.SplitAndConvert<int>(ids);

            return ToResponse(_CorecmsareaService.Delete(idArr));
        }

    }
}